//
//  VisitorTableController.swift
//  weibo
//
//  Created by 孙新 on 16/4/16.
//  Copyright © 2016年 孙新. All rights reserved.
//

import UIKit

class VisitorTableController: UITableViewController, VisitorViewDelegate {
    
  
    
    //用户是否登录
    var loginUser: Bool = false
    
    //在loadView方法里判断用户是否登录
    override func loadView() {
        loginUser ? super.loadView() : setUpVisitorView()
//        super.loadView()
//        self.navigationController?.navigationBar.setTitleVerticalPositionAdjustment(50, forBarMetrics: .Default)
    }
    
    private func setUpVisitorView(){
//        print("加载view") // 加载view成功 但不显示可能加让cell覆盖了？怎么移除tabelView上的cell    失败！！！
         view = visitorView
        
        //给导航控制器设置左右两边的登录按钮与注册按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登 录", style: .Plain, target: self, action: "loginClickButton")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注 册", style: .Plain, target: self, action: "registorClickButton")
        //给item添加背景图片
        navigationItem.leftBarButtonItem?.setBackgroundImage(UIImage(named: "searchbar_textfield_background"), forState: .Normal, barMetrics: .Default)
        navigationItem.leftBarButtonItem?.setBackgroundImage(UIImage(named: "searchbar_textfield_background"), forState: .Selected, barMetrics: .Default)
        navigationItem.rightBarButtonItem?.setBackgroundImage(UIImage(named: "searchbar_textfield_background"), forState: .Normal, barMetrics: .Default)
        navigationItem.rightBarButtonItem?.setBackgroundImage(UIImage(named: "searchbar_textfield_background"), forState: .Selected, barMetrics: .Default)
        //下面这个方法可以调整导航栏的位置
//        self.navigationController?.navigationBar.setTitleVerticalPositionAdjustment(50, forBarMetrics: .Default)
        
    }
    
 //他吗的不实现协议的方法老是变红 气死爹了
    func loginClickButton() {
        print("控制器调用了登录按钮点击事件")
    }
    
    func registorClickButton() {
        print("控制器调用了注册按钮点击事件")
    }
    

    //懒加载view
 lazy var visitorView:VisitorView = {
       let view = VisitorView()
        view.delegate = self
        return view
    }()

  

 


}
